package com.conversationboard.batch.jobs.bans;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class BanChecker implements Job {

	public void execute(JobExecutionContext context) throws JobExecutionException {

//		Connection connection = null;
//
//		try {
//
//			connection = Database.getConnection();
//
//			int banThreshold = Configuration.getInstance().getBanThreshold();
//
//			PreparedStatement statement = connection.prepareStatement(BatchQueries.GET_USERS_EXCEEDING_BAN_THRESHOLD);
//			statement.setInt(1, banThreshold);
//
//			statement.execute();
//
//			ResultSet resultSet = statement.getResultSet();
//
//			List<String> bannedUsers = new LinkedList<String>();
//
//			/* Ban all the users exceeding the threshold */
//
//			while (resultSet.next()) {
//
//				String loginId = resultSet.getString("banloginid");
//				int count = resultSet.getInt("total");
//
//				User systemUser = User.getSystemUser();
//
//				User user = User.get(loginId);
//
//				/* Don't ban site admins */
//
//				if (user.isSiteAdmin()) {
//					continue;
//				}
//
//				Mail mail = new Mail();
//				String body = Configuration.getInstance().getSiteName() + " System: " + user.getFullDisplayName() + " was suggest banned";
//				mail.sendToSiteAdmins("Suggest Ban", body);
//
//				String reason = "<strong>ILX SYSTEM</strong>: user has received ban requests from " + count + " users.";
//				user.ban(systemUser, reason, false);
//
//				bannedUsers.add(loginId);
//			}
//
//			statement.close();
//
//			/* Now clear out the cache and the database of records of people having voted to ban these users */
//
//			for (String loginId : bannedUsers) {
//				BanVoteCache.clearUserFromCache(loginId);
//			}
//
//		} catch (SQLException e) {
//			throw new JobExecutionException(e);
//		} catch (NamingException e) {
//			throw new JobExecutionException(e);
//		} catch (MessagingException e) {
//			throw new JobExecutionException(e);
//		} finally {
//			try {
//				Database.close(connection);
//			} catch (SQLException e) {
//				throw new JobExecutionException(e);
//			}
//		}

	}

}
